package cn.ad.enumration;

/**
 * 素材格式枚举类型 use for ad_material.material_format
 * 1 - jpg 2 - png 3 - gif 4 - text 5 - mp4 6 - flv
 * 
 * @author yujuan.zhang
 * @from 2016-06-20
 * @since V1.0
 *
 */
public enum MaterialFormat {

	MATERIALFORMAT_JPG(1, "jpg"), 
	MATERIALFORMAT_PNG(2, "png"), 
	MATERIALFORMAT_GIF(3, "gif"), 
	MATERIALFORMAT_TEXT(4, "text"),
	MATERIALFORMAT_MP4(5, "mp4"), 
	MATERIALFORMAT_FLV(6, "flv");

	private int value;
	private String description;
	
    private static java.util.HashMap<Integer, String> mappings;
    private static java.util.HashMap<String, Integer> maps;
    
    private synchronized static java.util.HashMap<Integer, String> getMappings() {
        if (mappings == null) {
        	mappings = new java.util.HashMap<Integer, String>();
        	for (MaterialFormat format : MaterialFormat.values()) {
        		mappings.put(format.value, format.description);
        	}
        }
        return mappings;
    }
    
    private synchronized static java.util.HashMap<String, Integer> getMaps() {
        if (maps == null) {
        	maps = new java.util.HashMap<String, Integer>();
        	for (MaterialFormat format : MaterialFormat.values()) {
        		maps.put(format.description, format.value);
        	}
        }
        return maps;
    }

	private MaterialFormat(int value, String description) {
		this.value = value;
		this.description = description;
	}

	public int getValue() {
		return this.value;
	}

	public String getDescription() {
		return this.description;
	}

	@Override
	public String toString() {
		return Integer.toString(this.value);
	}
	
	/***
	 * 根据素材格式的枚举值，获取对应的描述
	 * 
	 * @param value
	 *            素材格式的枚举值
	 * @return
	 */
	public static String forDescription(int value) {
		return getMappings().get(value);
	}

	/**
	 * 根据图片格式后缀名，获取对应的枚举值
	 * 
	 * @param description
	 *            图片格式对应的后缀名
	 * @return
	 */
	public static int forValue(String description) {
		return getMaps().get(description);
	}

}
